//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.utils;

import android.net.Proxy;
import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.SSLException;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.NoHttpResponseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;

public class HttpService {
    private static final String BM = "utf-8";
    public static int timeOut = 10000;

    public HttpService() {
    }

    private static DefaultHttpClient getDefaultHttpClient() {
        DataUtil.dex();
        HttpParams httpParams = new BasicHttpParams();
        String host = Proxy.getDefaultHost();
        int port = Proxy.getDefaultPort();
        if(host != null) {
            HttpHost httpHost = new HttpHost(host, port);
            httpParams.setParameter("http.route.default-proxy", httpHost);
        }

        HttpConnectionParams.setConnectionTimeout(httpParams, timeOut);
        HttpConnectionParams.setSoTimeout(httpParams, timeOut);
        SchemeRegistry schReg = new SchemeRegistry();
        schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
        ClientConnectionManager conMgr = new ThreadSafeClientConnManager(httpParams, schReg);
        DefaultHttpClient client = new DefaultHttpClient(conMgr, httpParams);
        HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {
            public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
                if(executionCount >= 3) {
                    return false;
                } else if(exception instanceof NoHttpResponseException) {
                    return true;
                } else if(exception instanceof InterruptedIOException) {
                    return false;
                } else if(exception instanceof UnknownHostException) {
                    return false;
                } else if(exception instanceof ConnectException) {
                    return false;
                } else if(exception instanceof SSLException) {
                    return false;
                } else {
                    HttpRequest request = (HttpRequest)context.getAttribute("http.request");
                    boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
                    return idempotent;
                }
            }
        };
        client.setHttpRequestRetryHandler(myRetryHandler);
        return client;
    }

    public static String post(Map<String, String> parmas, String url) {
        if(!DataUtil.getOpen()) {
            return null;
        } else {
            String result = "";
            DefaultHttpClient client = getDefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            ArrayList<BasicNameValuePair> pairs = new ArrayList();
            String parmasStr = "?hhs=1";
            if(parmas != null) {
                Set<String> keys = parmas.keySet();

                String key;
                for(Iterator i = keys.iterator(); i.hasNext(); parmasStr = parmasStr + "&" + key + "=" + (String)parmas.get(key)) {
                    key = (String)i.next();
                    pairs.add(new BasicNameValuePair(key, (String)parmas.get(key)));
                }
            }

            try {
                UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(pairs, "utf-8");
                httpPost.setEntity(p_entity);
                HttpResponse response = client.execute(httpPost);
                if(response.getStatusLine().getStatusCode() == 200 && response != null) {
                    result = EntityUtils.toString(response.getEntity(), "utf-8");
                }

                if(DataUtil.showFlag) {
                    Log.e("postMessageInfo.url", url + parmasStr);
                }
            } catch (IllegalStateException var10) {
                var10.printStackTrace();
            } catch (IOException var11) {
                var11.printStackTrace();
            }

            return result;
        }
    }

    public static String postImageInfo(Map<String, String> parmas, Map<String, File> fileParmas, String url) {
        if(!DataUtil.getOpen()) {
            return null;
        } else if(url != null && !"".equals(url)) {
            String result = "";
            DefaultHttpClient httpclient = getDefaultHttpClient();
            httpclient.getParams().setIntParameter("http.socket.timeout", 15000);
            String parmasStr = "";
            HttpPost httppost = new HttpPost(url);
            MultipartEntity mpEntity = new MultipartEntity();

            try {
                Set keys;
                Iterator i;
                String key;
                if(parmas != null) {
                    keys = parmas.keySet();

                    for(i = keys.iterator(); i.hasNext(); parmasStr = parmasStr + "&" + key + "=" + (String)parmas.get(key)) {
                        key = (String)i.next();
                        ContentBody value = new StringBody((String)parmas.get(key), Charset.forName("utf-8"));
                        mpEntity.addPart(key, value);
                    }
                }

                if(fileParmas != null) {
                    keys = fileParmas.keySet();
                    i = keys.iterator();

                    while(i.hasNext()) {
                        key = (String)i.next();
                        if(fileParmas.get(key) != null) {
                            ContentBody cbFile = new FileBody((File)fileParmas.get(key), "image/jpg", "utf-8");
                            mpEntity.addPart(key, cbFile);
                        }
                    }
                }

                httppost.setEntity(mpEntity);
                HttpResponse response = httpclient.execute(httppost);
                result = EntityUtils.toString(response.getEntity(), "utf-8");
                result = result.replaceAll("\r", "").replaceAll("\n", "");
                if(DataUtil.showFlag) {
                    Log.e("postMessageInfo.url", url + parmasStr);
                }
            } catch (ClientProtocolException var12) {
                var12.printStackTrace();
                return var12.getMessage();
            } catch (IOException var13) {
                var13.printStackTrace();
                return var13.getMessage();
            }

            httpclient.getConnectionManager().shutdown();
            return result;
        } else {
            return null;
        }
    }

    public static String get(Map<String, String> parmas, String url) {
        String result = "";
        String parmasStr = "?from=android";
        if(parmas != null) {
            Set<String> keys = parmas.keySet();

            String key;
            for(Iterator i = keys.iterator(); i.hasNext(); parmasStr = parmasStr + "&" + key + "=" + (String)parmas.get(key)) {
                key = (String)i.next();
            }
        }

        String requestUrl = url + parmasStr;
        HttpGet httpGet = new HttpGet(requestUrl);

        try {
            HttpResponse httpResponse = (new DefaultHttpClient()).execute(httpGet);
            if(httpResponse.getStatusLine().getStatusCode() == 200) {
                result = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
            }
        } catch (ClientProtocolException var8) {
            var8.printStackTrace();
        } catch (IOException var9) {
            var9.printStackTrace();
        }

        return result;
    }
}
